<template>
  <div style="height: 100%; width: 100%; position: relative">
    <div class="pagetop">
      <div class="top-deal">
        <el-button @click="btnQuery" icon="el-icon-search" type="primary" :disabled="bChangeFlag">查询</el-button>
        <el-button @click="btnAdd" icon="el-icon-plus" :disabled="bChangeFlag"> 新增</el-button>
        <el-button @click="btnDel" icon="el-icon-delete" :disabled="bChangeFlag">删除</el-button>
        <el-button @click="btnSave" icon="el-icon-document" :disabled="!bChangeFlag">保存</el-button>
        <el-button @click="btnCancel" icon="el-icon-close" :disabled="!bChangeFlag">取消</el-button>
        <el-button @click="btnExport" icon="el-icon-upload2" :disabled="bChangeFlag">导出</el-button>
        <!-- <el-button @click="btnTest" icon="el-icon-upload2" :disabled="bChangeFlag">测试按钮</el-button> -->
      </div>
    </div>
    <div class="pagecenter">
      <rm-layout-right splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="740">
        <template v-slot:fix>
          <div v-loading="bPageInitLoading" element-loading-spinner="el-icon-loading"
            element-loading-background="rgba(0, 0, 0, 0.8)" style="height: 100%">
            <rm-layout-top splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="400" :canDrag="false">
              <template v-slot:fix>
                <div class="pagecenter-right-top" style="">
                  <el-form :label-position="labelPosition" :model="mainData" :disabled="bNullFlag">
                    <table style="font-size: 12px">
                      <tr>
                        <td align="right" class="thwidth">规则ID</td>
                        <td>
                          <el-input v-model="mainData.multiitemruleid" class="thwidth1" readonly="readonly"> </el-input>
                        </td>
                        <td align="right">类别</td>
                        <td colspan="2">
                          <el-select v-model="mainData.ruleclass" placeholder="请选择" class="thwidth1" ref="input0"
                            @input="HasChange">
                            <el-option v-for="item in ruleclassOption" :key="item.value" :label="item.label"
                              :value="item.value"></el-option>
                          </el-select>
                        </td>
                        <td rowspan="4" colspan="2"><span style="color:blue;">【^】表示与参考值标志，<br />例：<br />[^2013031]
                            是参考高值，<br />[2013031^] 是参考低值。</span></td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth">创建人</td>
                        <td>
                          <el-input v-model="mainData.create_user" @input="HasChange" ref="input1"
                            @keyup.enter.native="NextFocus(1)" class="thwidth1" readonly="readonly"> </el-input>
                        </td>
                        <td align="right" class="thwidth">创建时间</td>
                        <td colspan="2">
                          <el-input v-model="mainData.create_dt" @input="HasChange" ref="input2"
                            @keyup.enter.native="NextFocus(2)" class="thwidth1" readonly="readonly"></el-input>
                        </td>
                        <td></td>
                        <td></td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth">规则名称</td>
                        <td>
                          <el-input v-model="mainData.rulename" @input="HasChange" ref="input3"
                            @keyup.enter.native="NextFocus(3)" maxlength="128"> </el-input>
                        </td>
                        <td colspan="2">
                          <el-checkbox true-label="1" false-label="0" v-model="mainData.isvalid"
                            @change="HasChange">有效</el-checkbox>
                        </td>
                        <td class="right-row">
                          <el-checkbox class="right-checkbox" true-label="1" false-label="0"
                            v-model="mainData.isreportshow" @change="HasChange">预判定</el-checkbox>
                          <span class="icon"><i class="el-icon-info"
                              style="font-size:14px;color: #78a4d7;padding-left:5px;" @click="icontip"></i></span>
                        </td>
                        <td></td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth">相应操作</td>
                        <td>
                          <el-select v-model="mainData.ruleaction" placeholder="请选择" class="thwidth1" @input="HasChange"
                            ref="input4" @keyup.enter.native="NextFocus(4)" @change="DataTableShowChange">
                            <el-option v-for="item in ruleactionOption" :key="item.value" :label="item.label"
                              :value="item.value"></el-option>
                          </el-select>
                        </td>
                        <td align="right" class="thwidth">上报周期(天)</td>
                        <td colspan="2">
                          <el-input v-model="mainData.cycledays" @input="HasChange" ref="input5"
                            @keyup.enter.native="NextFocus(5)" style="text-align: right"
                            onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" maxlength="10"></el-input>
                        </td>
                        <td></td>
                        <td></td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth">提示说明</td>
                        <td colspan="4">
                          <el-input type="textarea" :rows="2" v-model="mainData.describe" ref="input6"
                            @keyup.enter.native="NextFocus(6)" @input="HasChange"></el-input>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 40px" @click="btnInputClick('^')">^</el-button>
                        </td>
                        <td></td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth" rowspan="3">备注</td>
                        <td colspan="4" rowspan="3">
                          <el-input type="textarea" :rows="3" v-model="mainData.note" ref="input7"
                            @keyup.enter.native="NextFocus(7)" @input="HasChange"></el-input>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 40px" @click="btnInputClick('+')">+</el-button>
                          <el-button class="el-button--310" style="width: 40px" @click="btnInputClick('-')">-</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 40px" @click="btnInputClick('*')">*</el-button>
                          <el-button class="el-button--310" style="width: 40px" @click="btnInputClick('/')">/</el-button>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('()')">()</el-button>
                          <el-button class="el-button--310" style="width: 40px" @click="btnInputClick('')">""</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('and')">and</el-button>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('or')">or</el-button>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('>')">&gt;</el-button>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('>=')">&gt;=</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('<')">&lt;</el-button>
                          <el-button class="el-button--310" style="width: 40px"
                            @click="btnInputClick('<=')">&lt;=</el-button>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth" rowspan="2">计算公式</td>
                        <td colspan="4" rowspan="2">
                          <el-input type="textarea" :rows="3" v-model="mainData.calcformula1"
                            readonly="readonly"></el-input>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click.native="opendialog('pattype', '病人类型', pattypeOption)">病人类型</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click.native="opendialog('age', '年龄', '')">年龄</el-button>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click.native="opendialog('sex', '性别', sexOption)">性别</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click="btnInputClick('病人诊断')">病人诊断</el-button>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" class="thwidth" rowspan="2"></td>
                        <td colspan="4" rowspan="2">
                          <el-input type="textarea" :rows="3" v-model="mainData.calcformula"
                            @keyup.enter.native="NextFocus(8)" @input="HasChange" id="topdiv"></el-input>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click.native="opendialog('dept', '科室', deptOption)">申请科室</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click.native="opendialog('icd10', '科室', icd10Option)">病人诊断ICD10</el-button>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click.native="opendialog('specimentype', '标本类型', specimenOption)">标本类型</el-button>
                        </td>
                        <td>
                          <el-button class="el-button--310" style="width: 90px"
                            @click="rptitemdialogTableVisible = true">报告项目</el-button>
                        </td>
                      </tr>
                    </table>
                  </el-form>
                </div>
              </template>
              <div style="height: 100%; width: 100%; background-color: #ddccbb; top: 260px">
                <vxe-table ref="rDetailTable" :data="rDetailTableData" :loading="bLoading"
                  :keyboard-local-config="selKeyLocalConfig" :select-config="selectConfig"
                  :sort-config="{ trigger: 'cell' }"
                  :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border fit
                  height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column
                  resizable size="mini" stripe @edit-closed="rEditChange" :mouse-config="{ selected: true }"
                  show-header-overflow="tooltip" show-overflow="tooltip" @cell-dblclick="cellopendialog"
                  :edit-rules="checkdetailRules">
                  <vxe-table-column type="index" title="NO." width="50" align="center"></vxe-table-column>
                  <vxe-table-column field="rpt_itemcode" title="报告项目code" width="130" v-if="false"> </vxe-table-column>
                  <vxe-table-column field="rpt_itemname" title="报告项目" width="145" sortable></vxe-table-column>

                  <vxe-table-column field="specimen_codes" title="标本类型(双击)" width="135"
                    :edit-render="{ name: 'input', autoselect: true, attrs: { readonly: true } }"> </vxe-table-column>
                  <vxe-table-column field="rptunitids" title="报告单元(双击)" width="135"
                    :edit-render="{ name: 'input', events: { change: HasChange } }" header-align="center">
                  </vxe-table-column>
                  <vxe-table-column field="validdays" title="有效天数" width="80"
                    :edit-render="{ name: 'input', events: { change: HasChange } }" header-align="center" align="right">
                  </vxe-table-column>
                  <vxe-table-column field="defaultcalcval" title="默认值" width="53"
                    :edit-render="{ name: 'input', events: { change: HasChange } }" header-align="center" align="right">
                  </vxe-table-column>

                  <vxe-table-column field="ismaster" title="是否判定项目" width="80" align="center">
                    <template v-slot="{ row }">
                      <el-checkbox v-model="row.ismaster" true-label="1" false-label="0"
                        @change="HasChange"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="multiitemruleid" title="规则ID" width="50" header-align="center" align="right">
                  </vxe-table-column>
                  <!-- <template v-slot:fix>
                                      <div style="font-size: 17px; padding: 3px; background-color: #fff; text-align: center; font-weight: bold">
                                          <el-button @click="btnDetailAdd()" class="el-button--310">新增明细</el-button>
                                          <el-button @click="btnDetailDel()" class="el-button--310">删除明细</el-button>
                                      </div>
                                  </template> -->
                </vxe-table>
              </div>
            </rm-layout-top>
          </div>
        </template>
        <div style="height: 100%; top: 360px">
          <vxe-table ref="mainTable" :data="mainTableData" :loading="bLoading" :keyboard-local-config="keyLocalConfig"
            :row-class-name="lRowClassName" :select-config="selectConfig" :sort-config="{ trigger: 'cell' }"
            @current-change="CurrentChangeEvent" border fit height="auto" header-align="center" highlight-current-row
            highlight-hover-row highlight-hover-column resizable size="mini" stripe show-header-overflow="tooltip"
            show-overflow="tooltip">
            <vxe-table-column type="index" title="NO." align="center" width="40"></vxe-table-column>
            <vxe-table-column field="rulename" title="规则名称" width="165"></vxe-table-column>
            <vxe-table-column field="calcformula" title="计算公式" width="232"> </vxe-table-column>
            <vxe-table-column field="calcformula1" title="计算公式(辅助)" width="232" v-if="false"> </vxe-table-column>
            <vxe-table-column field="describe" title="提示说明" width="140"></vxe-table-column>
            <vxe-table-column field="note" title="备注" header-align="center" width="140"></vxe-table-column>
            <vxe-table-column field="ruleaction" title="相应操作" width="70" :formatter="format"></vxe-table-column>
            <vxe-table-column field="cycledays" title="上报周期(天)" width="75" header-align="center"
              align="right"></vxe-table-column>
            <vxe-table-column field="create_dt" title="创建时间" align="center" width="122"></vxe-table-column>
            <vxe-table-column field="create_user" title="创建人" align="center" width="60"></vxe-table-column>
            <vxe-table-column field="isvalid" title="是否有效" align="center" width="70">
              <template v-slot="{ row }">
                <el-checkbox v-model="row.isvalid" true-label="1" false-label="0" :disabled="true"></el-checkbox>
              </template>
            </vxe-table-column>
            <vxe-table-column field="isreportshow" title="预判定" align="center" width="100">
              <template v-slot="{ row }">
                <el-checkbox v-model="row.isreportshow" true-label="1" false-label="0" :disabled="true"></el-checkbox>
              </template>
            </vxe-table-column>
            <vxe-table-column field="ruleclassname" title="类别" align="center" width="120"></vxe-table-column>
            <vxe-table-column field="multiitemruleid" title="规则ID" header-align="center" align="right"
              width="73"></vxe-table-column>
          </vxe-table>
        </div>
      </rm-layout-right>
    </div>
    <!--多选弹窗--->
    <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle"
      :visible.sync="dialogCondvalue" :destroy-on-close="true">
      <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" :param="condTitle" :age="ageList"
        @changeAge="changeAge" @change="closedialog" :prono="'LIS848'" :LIS848radio="LIS848radio"></rm-SqlMultiple>
    </el-dialog>

    <!-- 标本类型/报告单元 -->
    <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle"
      :visible.sync="rowdialogvalue" :destroy-on-close="true">
      <rm-SqlMultiple :leftOption="rowoption1" :rightOption="rowoption2" :name="fieldname" :param="condTitle"
        @change="rowclosedialog"></rm-SqlMultiple>
    </el-dialog>

    <el-dialog width="900px" top="10px" :append-to-body="true" :close-on-click-modal="false" title="选择报告项目"
      :visible.sync="rpt_itemdialog" :destroy-on-close="true">
      <rm-pop-rptitem prgno="LIS117" @cancel="rpt_itemdialog = false" :isAllRpt="1" @selitem="rpt_itemchange"
        :rptunitid="txtrptunit"></rm-pop-rptitem>
    </el-dialog>

    <el-dialog top="10px" :append-to-body="true" :close-on-click-modal="false" title="选择报告项目"
      :visible.sync="rptitemdialogTableVisible" :destroy-on-close="true">
      <rm-pop-rptitem prgno="LIS117" @cancel="rptitemdialogTableVisible = false" :isAllRpt="1"
        @selitem="addrptitem1"></rm-pop-rptitem>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
import rmLayoutRight from "../../../rmcompents/rm-layout-right.vue";
export default {
  components: { rmLayoutRight },
  name: "LIS117",

  data() {
    return {
      bPageInitLoading: false,
      labelPosition: "right",
      mainTableData: [],
      mainData: {},
      txtrptunit: "",
      rDetailTableData: [],
      bLoading: false,
      selKeyLocalConfig: { isArrow: true },
      keyLocalConfig: { isDel: true, isTab: true, isEdit: true, isArrow: true },
      selectConfig: { tigger: "row" },
      bChangeFlag: false,
      ruleactionOption: [
        { value: "", label: "" },
        { value: "0", label: "提示" },
        { value: "1", label: "禁止审核" },
        { value: "2", label: "上报处理" },
      ],
      isinsertflag: "0", // 判断点击保存前的操作 0 修改 1 新增 2 删除

      checkdetailRules: {
        rpt_itemname: [{ required: true, message: "必须选择报告项目" }],
      },
      keyConfig: {
        isDel: true,
        isTab: true,
        isEdit: true,
      },
      LIS848radio: 1,
      condTitle: "",
      fieldname: "",
      ageList: [],
      option1: [],
      option2: [],
      rowoption1: [],
      rowoption2: [],

      pattypeOption: [], // 病人类型
      ruleclassOption: [], // 类别
      deptOption: [], // 科室
      specimenOption: [], //标本类型
      icd10Option: [], //icd10
      rptunitOption: [], // 报告单元
      sexOption: [
        { data: "1", display: "男" },
        { data: "2", display: "女" },
        { data: "3", display: "未知" },
      ],
      dialogCondvalue: false,
      multichktitle: "",
      rpt_itemdialog: false,
      selrow: {},
      rowdialogvalue: false,
      detailrow: [], // 右下选中行
      rptitemdialogTableVisible: false,
      isDelete: false,
      bNullFlag: false,
    };
  },
  created() {
    this.InitPage();
    this.btnQuery();
  },
  methods: {
    icontip() {
      this.$alert(" 预判定打勾的话，报告保存时就会执本规则的判定，可以提前标识出此份报告是否违反异常规则；不勾则在报告审核时才会进行规则判定", "信息", { dangerouslyUseHTMLString: true });
    },
    InitPage() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS117",
          method: "post",
          data: {
            action: "InitPage",
          },
        })
        .then((res) => {
          this.ruleclassOption = res.ruleclasslist;
          this.pattypeOption = res.pattypelist;
          this.deptOption = res.deptlist; // 科室
          this.specimenOption = res.specimenlist; //标本类型
          this.icd10Option = res.icd10list; //icd10
          this.rptunitOption = res.rptunitlist; // 报告单元
        })
        .catch((err) => { });
    },
    QueryData(rowid) {
      this.isinsertflag = "0";
      this.$tool
        .request({
          url: "LIS/LIS1/LIS117",
          method: "post",
          data: {
            action: "QueryData",
          },
        })
        .then((res) => {
          this.mainTableData = res.data;

          if (res.data.length > 0) {
            if (rowid != null && rowid != "") {
              var row = this.mainTableData.find((m) => m.multiitemruleid == rowid);
              this.$refs.mainTable.setCurrentRow(row);
              this.mainData = XEUtils.clone(row, true);
              // this.mainData.calcformula1 = this.mainData.calcformula1;
              this.QueryDetailData(row.multiitemruleid);
            } else {
              this.mainData = XEUtils.clone(res.data[0], true);
              //  this.mainData.calcformula1 = this.mainData.calcformula1;
              this.mainData.validflag = parseInt(res.data[0].validflag);
              this.$refs.mainTable.setCurrentRow(res.data[0]);
              this.QueryDetailData(res.data[0].multiitemruleid);
            }
            this.bNullFlag = false;
          } else {
            this.mainTableData = [];
            this.mainData = [];
            this.rDetailTable = [];
            this.rEditChange = [];
            this.bNullFlag = true;
          }
        });
    },
    QueryDetailData(multiitemruleid) {
      this.bLoading = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS117",
          method: "post",
          data: {
            action: "QueryDetail",
            multiitemruleid: multiitemruleid,
          },
        })
        .then((res) => {
          this.rDetailTableData = res.data;
          this.bLoading = false;
        })
        .catch(() => {
          this.bLoading = false;
        });
    },
    btnQuery() {
      this.QueryData("");
    },
    btnAdd() {
      this.mainData = {
        multiitemruleid: "",
        ruleclass: "",
        create_user: "",
        create_user: "",
        rulename: "",
        isvalid: "1",
        isreportshow: "0",
        ruleaction: " ",
        cycledays: "",
        describe: "",
        note: "",
        calcformula1: "",
        calcformula: "",
      };
      this.showDisabled = true;
      this.bChangeFlag = true;
      this.isinsertflag = "1";
      this.rDetailTableData = [];
      this.bNullFlag = false;
    },
    DataTableShowChange() { },
    btnDel() {
      // 主记录删除 同时要删除相应明细
      var delrow = this.$refs.mainTable.getCurrentRow();
      this.$confirm('确定删除判断规则名称为<b style="color:red">' + delrow.rulename + "</b>的记录吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        dangerouslyUseHTMLString: true,
        type: "warning",
      })
        .then(() => {
          this.actionindex = "D";
          this.isinsertflag = "2";
          this.confirmDel();
        })
        .catch((e) => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //删除 -- 确认删除
    async confirmDel() {
      try {
        var delrow = this.$refs.mainTable.getCurrentRow();
        if (delrow) {
          var alld = this.$refs.mainTable.tableData;
          var rowindex = alld.indexOf(delrow);
          this.isDelete = true;
          await this.btnSave().then(() => {
            this.isDelete = false;
            this.btnQuery();
            // this.$refs.mainTable.remove(delrow);
            // this.mainTableData.splice(rowindex, 1);
            // let havedata = this.$refs.mainTable.tableData;
            // if (havedata.length > 0) {
            //     if (rowindex >= havedata.length) rowindex = havedata.length - 1;
            //     let selectrow = havedata[rowindex];
            //     this.HightLightRow(selectrow);
            // } else {
            //     this.HightLightRow(false);
            // }
          });
        }
      } catch (e) {
        console.info("error:==" + e);
      }
    },
    btnSave() {
      let currtrow = this.$refs.mainTable.getCurrentRow();
      console.info("isinsertflag=== " + this.isinsertflag);

      var ruleclass = this.mainData.ruleclass;
      if (ruleclass == "" || ruleclass == null) {
        this.$alert("【类别】不能为空，请选择");
        return;
      }

      var rulename = this.mainData.rulename;
      if (rulename == "" || rulename == null) {
        this.$alert("【规则名称】不能为空，请填写");
        return;
      } else {
        if (rulename.length > 64) {
          this.$alert("【规则名称】长度大于64，请重新填写");
          return;
        }
      }

      var ruleaction = this.mainData.ruleaction;
      if (ruleaction == "" || ruleaction == null) {
        this.$alert("【相应操作】不能为空，请选择");
        return;
      }

      var calcformula = this.mainData.calcformula;
      if (calcformula == "" || calcformula == null) {
        this.$alert("【计算公式】不能不能为空，请选择");
        return;
      }

      var describe = this.mainData.describe;
      if (describe == "" || describe == null) {
        this.$alert("【提示说明】不能为空，请填写");
        return;
      } else {
        if (describe.length > 64) {
          this.$alert("【提示说明】长度大于256，请重新填写");
          return;
        }
      }

      // 执行保存
      let tabledata = this.$refs.rDetailTable.getRecordset();

      this.$tool
        .request({
          url: "LIS/LIS1/LIS117",
          method: "post",
          data: {
            action: "SaveData",
            dataList: tabledata,
            mainData: this.mainData,
            isinsertflag: this.isinsertflag,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.$message({
              message: "保存成功！",
              type: "success",
            });

            if (!this.isDelete) {
              this.QueryData(currtrow.multiitemruleid);
            } else {
              this.QueryData("");
            }

            //this.$refs.mainTable.setCurrentRow(currtrow);
            this.bChangeFlag = false;
          } else {
            this.$alert({
              message: "保存失败！" + res.errmsg,
              type: "warning",
            });
            this.bChangeFlag = false;
          }
        });
    },
    btnCancel() {
      let row = this.$refs.mainTable.getCurrentRow();
      this.$confirm("您确定要取消这次改动吗？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.bChangeFlag = false;
          this.QueryData("");
        })
        .catch((e) => { });
    },
    btnExport() {
      this.$refs.mainTable.exportCsv({
        filename: "LIS117  复杂项目判定规则",
      });
    },
    btnDetailAdd(code, name) {
      let data = this.$refs.rDetailTable.tableData;
      let len = data.length;
      let row = data.find((item) => item.rpt_itemcode == code);
      if (row) return;
      //return (len + 1) * 10;
      this.$refs.rDetailTable.insertAt(
        {
          seq: (len + 1) * 10,
          specimen_codes: "ALL",
          rptunitids: "ALL",
          validdays: 30,
          ismaster: "1",
          rpt_itemname: name,
          rpt_itemcode: code,
        },
        -1
      ),
        (this.bChangeFlag = true);
    },
    btnDetailDel() {
      try {
        var delrow = this.$refs.rDetailTable.getCurrentRow();
        if (delrow) {
          var alld = this.$refs.rDetailTable.tableData;
          var rowindex = alld.indexOf(delrow);
          this.$refs.rDetailTable.remove(delrow);
          let havedata = this.$refs.rDetailTable.tableData;
          if (havedata.length > 0) {
            if (rowindex >= havedata.length) rowindex = havedata.length - 1;
            let selectrow = havedata[rowindex];
            this.$refs.rDetailTable.setCurrentRow(selectrow);
          } else {
            this.$refs.rDetailTable.setCurrentRow(null);
          }
          this.bChangeFlag = true;
        }
      } catch (e) {
        console.log("error", e);
      }
    },
    rEditChange({ row, column, rowIndex }) { },
    // 左侧主表
    lRowClassName({ row, rowIndex }) { },
    // 行改变事件
    CurrentChangeEvent({ row }) {
      this.mainData = XEUtils.clone(row, true);
      this.QueryDetailData(this.mainData.multiitemruleid);
      this.bChangeFlag = false;
    },
    //数据发生改变 -- 按钮禁用/可用切换
    HasChange() {
      this.bChangeFlag = true;
    },
    opendialog(type, name, option) {
      if (type == "age") {
        this.ageMultipleChk("", type, name);
      } else {
        this.popMultipleChk(type, type, option, name);
        this.dialogCondvalue = true;
      }
    },
    ageMultipleChk(e, fieldname, title) {
      console.log(e, fieldname, title);
      this.ageList = e.split(",");
      this.fieldname = fieldname;
      this.condTitle = title;
      this.multichktitle = title;
      this.dialogCondvalue = true;
    },
    popMultipleChk(e, fieldname, option, title) {
      let temp = XEUtils.clone(option, true);
      this.option1 = [];
      this.option2 = [];
      if (e != "") {
        let k = e.split(",");
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item);
          if (ndata != undefined && ndata != null) {
            this.option2.push(ndata);
          }
        });
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.option1.push(item);
          }
        });
      } else {
        this.option1 = temp;
      }
      this.fieldname = fieldname;
      this.multichktitle = title;
      this.condTitle = title; //!问题出在这里 没更换condTitle
      this.dialogCondvalue = true;
    },
    closedialog(value, name, textvalue, validflag) {
      console.info("1111111111111");
      var msg = "";
      if (name != "condvalue") {
        msg = this.splitAndRecombination(value, name, validflag);
      } else {
        msg = this.agesplitAndRecombination(value);
      }

      this.mainData.calcformula += "  " + msg;
      this.mainData.calcformula1 = this.mainData.calcformula;
      this.bChangeFlag = true;

      this.dialogCondvalue = false;
    },
    splitAndRecombination(value, name, iscontain) {
      //  生成的例子： "[病人诊断]" not in ("1","2")
      var strmsg = "";
      var strname = "";
      var str = "";
      if (value != "close") {
        let k = value.split(",");

        if (name == "pattype") {
          strname = '"[病人类型]"';
        } else if (name == "sex") {
          strname = '"[性别]"';
        } else if (name == "dept") {
          strname = '"[申请科室]"';
        } else if (name == "icd10") {
          strname = '"[病人诊断ICD10]"';
        } else if (name == "specimentype") {
          strname = '"[标本类型]"';
        }
        if (iscontain == "1") {
          strname += "  in  ";
          k.forEach((item) => {
            str += '"' + item + '"' + ",";
          });
          strmsg = strname + "(" + str.substring(0, str.length - 1) + ")";
        } else {
          for (let i = 0; i < k.length; i++) {
            if (k.length - i != 1) {
              strmsg += strname + "<>" + '"' + k[i] + '"' + " and  ";
            } else {
              strmsg += strname + "<>" + '"' + k[i] + '"';
            }
          }
        }
      }

      return strmsg;
    },
    agesplitAndRecombination(value) {
      var msg = "";
      if (value != "close") {
        var str = value.split(",");
        for (let i = 0; i < str.length; i++) {
          var estr = str[i].split("-");
          var strmsg = "([年龄]>=" + estr[0] + "  and   [年龄]<=" + estr[1] + ")";
          if (str.length - i == 1) {
            msg += strmsg;
          } else {
            msg += strmsg + "  or  ";
          }
        }
      }

      return msg;
    },

    changeAge(action, agestr) {
      console.log(agestr);
      if (action == "change") {
        this.closedialog(agestr, "condvalue", agestr, "1");
      } else {
        this.dialogCondvalue = false;
      }
    },
    format({ cellValue, row, column }) {
      if (column.property == "ruleaction") {
        if (row.ruleaction == "0") {
          return "提示";
        } else if (row.ruleaction == "1") {
          return "禁止审核";
        } else if (row.ruleaction == "2") {
          return "上报处理";
        }
      }
    },
    popGetRow(row) {
      this.rptItemRow = row;
      this.bDlgRptItem = true;
    },
    // AddRptItem(c, v, row) {
    //     this.rptItemRow.rpt_itemcode = c;
    //     this.rptItemRow.rpt_itemname = row.itemcode_en + " " + v + " " + c;
    //     this.bChangeFlag = true;
    //     this.bDlgRptItem = false;
    // },
    cellopendialog({ row, column }) {
      console.info("column==" + column);
      this.detailrow = row;
      if (column.property == "rpt_itemname") {
        // this.selrow = row;
        // this.rpt_itemdialog = true;
      } else if (column.property == "specimen_codes") {
        this.rowPopMultipleChk(row.specimen_codes, "specimen_codes", this.specimenOption, "标本类型");
      } else if (column.property == "rptunitids") {
        this.rowPopMultipleChk(row.rptunitids, "rptunitids", this.rptunitOption, "报告单元");
      }
    },
    rowPopMultipleChk(e, fieldname, option, title) {
      let temp = XEUtils.clone(option, true);
      this.rowoption1 = [];
      this.rowoption2 = [];
      if (e != "" && e != null) {
        let k = e.split(",");
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item);
          if (ndata != undefined && ndata != null) {
            this.rowoption2.push(ndata);
          }
        });
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.rowoption1.push(item);
          }
        });
      } else {
        this.rowoption1 = temp;
      }
      this.fieldname = fieldname;
      this.multichktitle = title;
      this.condTitle = title; //!问题出在这里 没更换condTitle
      this.rowdialogvalue = true;
    },
    rowclosedialog(value, name, textvalue, validflag) {
      if (name == "specimen_codes") {
        this.detailrow.specimen_codes = value == "" ? "ALL" : value;
      } else if (name == "rptunitids") {
        this.detailrow.rptunitids = value == "" ? "ALL" : value;
      }
      this.bChangeFlag = true;
      this.rowdialogvalue = false;
    },
    rpt_itemchange(code, name) {
      this.selrow.rpt_itemcode = code;
      this.selrow.rpt_itemname = name;
      this.bChangeFlag = true;
      this.rpt_itemdialog = false;
    },
    //把插入的字段或值放到当前光标所在位置
    InputCurrentPos(myValue, addspace) {
      var myField = document.getElementById("topdiv");
      if (myField.selectionStart || myField.selectionStart === 0) {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        this.mainData.calcformula = myField.value.substring(0, startPos) + (addspace ? " " : "") + myValue + (addspace ? " " : "") + myField.value.substring(endPos, myField.value.length);
        this.$nextTick(() => {
          myField.selectionStart = startPos + myValue.length + 2;
          myField.selectionEnd = startPos + myValue.length + 2;
        }); // 这句是重点, 圈起来
        myField.focus();
        myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
      } else {
        this.mainData.calcformula += (addspace ? " " : "") + myValue + (addspace ? " " : "");
      }
    },
    btnInputClick(name) {
      if (name == "病人诊断") {
        this.mainData.calcformula += "  " + '"[病人诊断]"';
      } else if (name != "") {
        //^是加方括号中间的，不要加空格
        let addspace = name != "^";
        this.InputCurrentPos(name, addspace);
      } else {
        this.mainData.calcformula += "  " + '""';
      }
      this.mainData.calcformula1 = this.mainData.calcformula;
      this.bChangeFlag = true;
    },
    addrptitem1(c, n, row) {
      this.mainData.calcformula1 = this.mainData.calcformula;
      this.mainData.calcformula += "  [" + c + "]  " + "  ";
      this.mainData.calcformula1 += "  [" + n + "]  " + "  ";
      this.rptitemdialogTableVisible = false;
      this.btnDetailAdd(c, n);
    },
    btnTest() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS117",
          method: "post",
          data: {
            action: "test",
          },
        })
        .then((res) => {
          this.$message({
            message: res.errcode + "====" + res.errmsg,
            type: "success",
          });
        });
    },
  },
};
</script>
<style scoped>
.pagetop {
  width: 100%;
  height: 35px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.search-title {
  margin: 0 5px 0 20px;
  font-size: 12px;
}

.top-deal {
  right: 5px;
  position: absolute;
  top: 5px;
  display: flex;
  align-items: center;
}

.thwidth {
  width: 80px;
}

.thwidth1 {
  /* width: 250px; */
}

.autopart {
  top: 280px !important;
}

::v-deep.el-checkbox__input.is-disabled+span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}

::v-deep.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #000000;
}

::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner+.el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}

::v-deep.popdialogstyle tr td div .el-input__inner {
  border: 1px solid rgba(255, 254, 254, 0) !important;
  background-color: rgba(255, 254, 254, 0) !important;
}

.vxe-table--header {
  display: table-cell !important;
}

.pagecenter-right-top {
  width: 100%;
  border: 1px solid #ccc;
  height: 400px;
}

::v-deep .right-row {
  align-items: center;
  display: flex;
  line-height: 22px;
}

::v-deep .right-checkbox .el-checkbox__label {
  line-height: 22px !important;
}

::v-deep .right-row .el-icon-info {
  margin-top: 6px;
  font-size: 15px !important;
}
</style>
